///GeoUSBHID definitions
#ifndef CGEOUSBHID__MODULE_INC
#define CGEOUSBHID__MODULE_INC
#define SIZE_OF_HID_USB_PACKET 64

#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#ifdef linux
#include <sys/types.h>
#include <sys/socket.h>
#include <pthread.h>
#else
#include <windows.h>
#include <io.h>
#endif

typedef enum eGEO_MSG_TYPES{
	GEO_CMD,
	GEO_SETUP_GPIO,
	GEO_SET_GPIO,
	GEO_GET_GPIO,
	GEO_SETUP_ADC,
	GEO_READ_ADC,
	GEO_SETUP_DAC,
	GEO_WRITE_DAC,
	GEO_SETUP_TIMER,
	GEO_SET_TIMER,
	GEO_WRITE_SPI_DATA,
	GEO_READ_SPI_DATA,
	GEO_SET_STATE_MACHINE,
	GEO_GET_FW_REVISION,
	GEO_PEEK,
	GEO_POKE,
	NUMBER_OF_GEO_MESSAGE_TYPES
}type_eGEO_MSG_TYPES;

#ifdef _WIN32
DWORD WINAPI USBThread(LPVOID data);
#elif __linux__
void *USBReadThreadL(void *data);
#endif

class CCgeousbhid
{
public:

    CCgeousbhid();
    ~CCgeousbhid();

    int geo_control_message(unsigned char *msg, int nbytes);
    int geo_read_message_blocked(unsigned char *msg, int nbytes);

    int  geostd;
protected:

#ifdef _WIN32
	HANDLE m_thread;
	DWORD m_threadId;
#elif __linux__
	pthread_t m_thread;
#endif
    bool bUSBReadThread_Running;


private:

    ssize_t geousbhid_control_UsbRawWrite(size_t count, unsigned char *data);
    ssize_t geousbhid_control_UsbRawRead(size_t count, unsigned char *data);
    int sendFWCmd(size_t count, unsigned char *data);
    int recvFWCmd(size_t count, unsigned char *data);
    size_t lerror;
    double fVREF_per_bit;

    int error;
    unsigned char cUSB_cmd[SIZE_OF_HID_USB_PACKET];
    unsigned char cUSB_response[SIZE_OF_HID_USB_PACKET];
    bool bUSBDataReady, bUSBReadError;
    int bytes_read, USBReadError;
    unsigned int *hw_blocked_count;

#ifdef linux
	static void *USBReadThreadL(void *data);
	struct thread_fun_args
	{
		CCgeousbhid* This ;
		void* actual_arg ;
		thread_fun_args( CCgeousbhid* t, void* p )
			: This(t), actual_arg(p) {}
	};
#endif
};

#endif ///CGEOUSBHID__MODULE_INC



